package info.nene_loveplus.controller.admin;

import info.nene_loveplus.model.blog.Entry;
import info.nene_loveplus.service.BlogService;

import org.slim3.controller.Navigation;
import org.slim3.util.StringUtil;

public class EditController extends AbstractAdminController {

	private BlogService blogService = new BlogService();

	@Override
	public Navigation doRun() {
		if (StringUtil.isEmpty(param("key"))) {
			return forward("error.jsp");
		}

		Entry e = blogService.findById(asString("key"));
		requestScope("title", e.getTitle());
		requestScope("content", e.getContent().getValue());
		if (e.getAudioFileRef().getModel() != null) {
			requestScope("audioFileUrl", e.getAudioFileRef().getModel()
					.getUrl());
		}

		return forward("dashboard.jsp");
	}
}
